package it.polimi.swKnights.SWIMv2.ejb.administration;

import it.polimi.swKnights.SWIMv2.ejb.entityBeans.BannedUser;
import it.polimi.swKnights.SWIMv2.ejb.entityBeans.RegisteredUser;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 * Session Bean implementation class BanController
 */
@Stateless
public class BannedUtility extends AdministrationBean implements
		BannedUtilityLocal
{

	@PersistenceContext(unitName = "swimv2-manager")
	private EntityManager manager;

	@Override
	public void endBanUser(BannedUser bannedUser)
	{
		try
		{
			RegisteredUser user = this.createUser(bannedUser,
					RegisteredUser.class);
			this.manager.remove(bannedUser);
			this.manager.persist(user);
		}
		catch (Exception e)
		{
			e.printStackTrace();
			System.err.println("Errore in automatic routine of end ban");
		}
	}

}
